<template>
  <div class="navbar">
    <div class="header-font">{{ title }}</div>
    <div class="right-menu">
      <div style="margin: 6px 0 0 0;">
        <div style="float:left;margin: -4px -26px 0 0;">
          <el-dropdown class="avatar-container" trigger="click">
            <div class="avatar-wrapper">
              <!-- <img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar"> -->
              <!-- <span style="color: #fff;">{{ user.name }}</span>
              <i style="color: #fff;margin: -7px 0 0 0;" class="el-icon-caret-bottom" /> -->
              <div style="margin: 6px 0 0 0;">
                <div style="float:left;margin-right: 10px;">
                  <svg-icon class="svgClass" icon-class="shezhi" />
                </div>
              </div>
            </div>
            <el-dropdown-menu slot="dropdown" class="user-dropdown">
              <el-dropdown-item divided>
                <router-link :to="{ name: 'Dashboard'}">
                  <svg-icon icon-class="dashboard" /><span>&nbsp;&nbsp;首页</span>
                </router-link>
              </el-dropdown-item>
              <el-dropdown-item divided>
                <router-link :to="{ name: 'UserCenter'}">
                  <svg-icon icon-class="headUser" /><span>&nbsp;&nbsp;个人中心</span>
                </router-link>
              </el-dropdown-item>
              <!-- <el-dropdown-item divided @click.native="logout">
                <svg-icon icon-class="headlogout" />
                <span>退出登录</span>
              </el-dropdown-item> -->
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div style="float:left;margin-right: 22px;" @click="logout">
          <svg-icon class="svgClass" icon-class="guanji" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { Message } from 'element-ui'
export default {
  components: {
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'title',
      'logo',
      'user'
    ])
  },
  mounted() {},
  methods: {
    async logout() {
      const res = await this.$store.dispatch('user/logout')
      if (res.code === 200) {
        Message({
          message: '退出成功!',
          type: 'success',
          showClose: true,
          center: true,
          duration: 2 * 1000
        })
        this.$router.push('/login')
      } else {
        Message({
          message: res.msg || 'Error',
          type: 'error',
          showClose: true,
          center: true,
          duration: 2 * 1000
        })
      }
      // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  // background: #fff;
  // box-shadow: 0 1px 4px rgba(0,21,41,.08);
  background:#252532;
  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }

  .breadcrumb-container {
    float: left;
  }
  .header-font{
    display: inline-block;
    color: #fff;
    font-weight: 600;
    font-size: 24px;
    margin: 13px 0 13px 32px;
    }
  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
